package com.coollang.smartbra.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.coollang.smartbra.base.BaseFragment;
import com.coollang.smartbra.fragment.GoalFragment;
import com.coollang.smartbra.fragment.SetUserInformationFragment;
import com.coollang.smartbra.fragment.StrengthFragment;

import java.util.HashMap;

public class WelcomePagerAdapter extends FragmentStatePagerAdapter {
    // 缓存所有的fragment对象
    public HashMap<Integer, BaseFragment> mFragmentMap = new HashMap<Integer, BaseFragment>();
    private BaseFragment mBaseFragment;

    public WelcomePagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        mBaseFragment = mFragmentMap.get(position);
        if (mBaseFragment == null) {
            switch (position) {
                case 0:
                    mBaseFragment = new GoalFragment();
                    break;
                case 1:
                    mBaseFragment = new StrengthFragment();
                    break;
                case 2:
                    mBaseFragment = new SetUserInformationFragment();
                    break;
                default:
                    break;
            }
            mFragmentMap.put(position, mBaseFragment);
        }
        return mBaseFragment;
    }

    @Override
    public int getCount() {
        return 3;
    }
}
